//
//  YAYIAppointListCell.m
//  YAYIDoctor
//
//  Created by hxp on 16/5/3.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIAppointListCell.h"

@implementation YAYIAppointListCell


+ (instancetype)cellWith:(UITableView *)tableview
{
    static NSString *cellID = @"appointListCell";
    
    YAYIAppointListCell *cell = [tableview dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYIAppointListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}


-(void)setModel:(YAYIOrderPatientModel *)model
{
    _model = model;
    
    // 这里显示时间段
    self.date.text = [NSString dateString:model.createtime];
    self.appoinView.model = model;
}


-(void)createViews
{
    self.line = [UILabel new];
    self.line.backgroundColor = [UIColor colorWithRed:83/255.0 green:165/255.0 blue:243/255.0 alpha:1];
    [self.contentView addSubview:self.line];
    
    self.point = [UILabel new];
    self.point.backgroundColor = [UIColor whiteColor];
    self.point.layer.borderColor = YAYIColor(83, 165, 243).CGColor;
    self.point.layer.borderWidth = 2;
    self.point.layer.masksToBounds = YES;
    [self.contentView addSubview:self.point];
    
    self.date = [UILabel new];
    self.date.textColor = [UIColor lightGrayColor];
    self.date.font = [UIFont systemFontOfSize:font12];
    [self.contentView addSubview:self.date];
    
    if (self.appoinView == nil) {
        self.appoinView = [[YAYIAppointView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:self.appoinView];
        self.appoinView.clipsToBounds = YES;
        self.appoinView.layer.cornerRadius = 5;
        self.appoinView.layer.borderWidth = 1;
        self.appoinView.layer.borderColor = YAYIColor(200, 200, 200).CGColor;
    }
   
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(0));
        make.left.equalTo(@(18));
        make.height.mas_equalTo(self.contentView.mas_height);
        make.width.equalTo(@(1));
    }];
    self.point.layer.cornerRadius = 4;
    
    [self.point mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.line.mas_top).with.offset(10);
        make.centerX.mas_equalTo(self.line.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(8, 8));
    }];
    [self.date mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.point.mas_centerY);
        make.left.mas_equalTo(self.point.mas_right).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];
//    self.appoinView.frame = CGRectMake(34, 44, 280, CGRectGetHeight(self.contentView.frame));
    self.appoinView.frame = CGRectMake(34, 44, SCREEN_width - 34 - 20, 120);
    //[self.appoinView createViews];;
}


#pragma mark - 工具方法
- (NSString *)periodWithTimStamp:(NSInteger)timeStamp timeLong:(NSInteger)timeLong
{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"HH:mm";
    
    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:timeStamp + timeLong];
    NSString *startTimeStr = [formatter stringFromDate:startDate];
    NSString *endTimeStr = [formatter stringFromDate:endDate];
    
    return [NSString stringWithFormat:@"%@ - %@", startTimeStr, endTimeStr];
}



@end
